<?php

require_once BASE_PATH.'application/models/basedao'.EXT;

class misembarazosDAO extends baseDAO {
	
	var $table = 'mis_embarazos';
	var $key   = 'id_mis_embarazos';
	var $sql   = '';

	function __construct()
	{
	    parent::__construct();
	}
	function _defaultSQL()
	{
		$this->db->select('id_mis_embarazos, id_embarazada, num_embarazo, fecha_inicio, fecha_fin');
	}
	function insert_batch($data){
		$result = $this->db->insert_batch($this->table, $data); 
		return $result;  
	    }
	
	function getFechaInicial($id_embarazada){
		    $this->_defaultSQL();
		    $this->db->select_max('num_embarazo');
		    $this->db->where(array("id_embarazada ="=>$id_embarazada));
		    $this->db->limit(1);
		    $query = $this->db->get($this->table);
		    return $query->result_array();
	    }
	
	function getNumberOfPregnancies($id_embarazada) {
		$this->_defaultSQL();
		$this->db->select_max('num_embarazo');
		$this->db->where(array("id_embarazada ="=>$id_embarazada));
		$this->db->limit(1);
		$result = $this->db->get($this->table);
		$num = $result->num_rows();
		if ($num > 0) {
			$row = $result->first_row('array');
			return $row['num_embarazo'];
		}else{
			return 0;
		}
	}
	
	function get_last_row($id_embarazada)
	{
		$this->_defaultSQL();
		$this->db->where('id_embarazada', $id_embarazada);
		$this->db->order_by('id_mis_embarazos', 'DESC'); 
		$this->db->limit(1);
		$query = $this->db->get($this->table);
		return $query->result_array();
	}
	
	function update($id_mis_embarazos, $data)
	{
		$this->db->where('id_mis_embarazos', $id_mis_embarazos);
		$result = $this->db->update($this->table, $data);
		return $result;
	}
}

?>